# -*-coding:utf-8-*-
"""
@project: python-project
@Time: 2024-08-09 16:49
@Author: Loneliness_Burial
@File: 系统内存与磁盘检测.py
@Motto: 深情不改必坠死海
@software: pycharm
@version: python 3.7
"""

import psutil


def memissue():
    print('内存信息：')
    mem = psutil.virtual_memory()  # 获取内存信息
    # 单位换算为MB
    memtotal = mem.total / 1024 / 1024
    memused = mem.used / 1024 / 1024
    membaifen = str(mem.used / mem.total * 100) + '%'

    print('已使用内存: ', '%.2fMB' % memused)
    print('内存总量为: ', '%.2fMB' % memtotal)
    print('内存使用百分比: ', membaifen)


def cuplist():
    print('磁盘信息: ')
    disk = psutil.disk_partitions()
    # 对每个磁盘占用率进行统计
    for i in disk:
        diskuse = psutil.disk_usage(i.mountpoint)
        # 单位换算为GB
        diskused = diskuse.used / 1024 / 1024 / 1024
        disktotal = diskuse.total / 1024 / 1024 / 1024
        diskbaifen = diskused / disktotal * 100
        print('磁盘路径: ', i.mountpoint)
        print('已使用磁盘空间: ', '%.2fGB' % diskused)
        print('磁盘总量: ', '%.2fGB' % disktotal)
        print('磁盘使用百分比: ', '%.2f' % diskbaifen)


memissue()
print('*******************')
cuplist()
